<template>
  <!-- <Wrap :showHead="false"> -->
  <!-- <view class="page-head">
      <statusBar></statusBar>
      绑定企业
    </view> -->
  <view class="page">
    <!-- <image
      class="bg"
      :src="imgBaseUrlV0 + 'enterprise-binding-bg.png'"
      mode="aspectFill"
    ></image> -->
    <view class="main">
      <view class="intro bind">绑定企业</view>
      <!-- <view class="intro en">Binding Enterprises</view> -->
      <view class="intro hint">输入企业编号</view>
      <input
        v-model="company_number"
        class="intro-input"
        height="90"
        placeholder="请输入企业编号"
        type="text"
        :trim="true"
        :auto-focus="true"
      />
      <view class="v-label">该编号可联系润滑卫士客服获取</view>
      <button type="primary" class="btn btn-primary" @click="submit">
        提交
      </button>
    </view>

    <!-- <u-toast ref="uToast" /> -->
    <Message ref="message"></Message>
  </view>
  <!-- </Wrap> -->
</template>

<script>
import { putEnterpriseBinding } from "@/common/api/enterprise.js";
import { mapState, mapMutations, mapActions } from "vuex";
import detailModule from "@/common/mixins/detail-module";
import { imgBaseUrl, imgBaseUrlV0 } from "@/common/config/index";
import Wrap from "@/pages/login/components/wrap";
export default {
  mixins: [detailModule],
  components: {
    Wrap,
  },
  computed: {
    ...mapState("User", ["userInfo"]),
  },
  data() {
    return {
      company_number: "",
      imgBaseUrl,
      imgBaseUrlV0,
      iconUrl: imgBaseUrlV0 + "info.png",
    };
  },
  onLoad() {},
  methods: {
    ...mapMutations("User", ["setUserInfo", "setToken"]),
    ...mapActions("User", ["getUserInfo"]),
    submit() {
      let company_number = this.company_number.trim();
      if (!company_number) {
        this.message.error("请输入企业编号");
      } else {
        uni.showLoading({
          title: "绑定中",
        });
        return putEnterpriseBinding({
          company_number,
        })
          .then(async (res) => {
            uni.hideLoading();
            if (res.code !== this.$ERR_OK) {
              return this.message.error(res.message || "提交失败");
            }
            let data = res.data || {};
            let token = data.token;
            if (token) {
              this.setToken(data);
              await this.getUserInfo()
                .then((res) => {})
                .catch((err) => {
                  uni.hideLoading();
                });
            }

            uni.hideLoading();
            return this.showModal({
              title: "提示",
              content: "绑定成功,点击返回上一页",
              showCancel: false,
              success: (r) => {
                this.$Router.go(-1);
                uni.$emit("change-page", 2);
              },
            });
          })
          .catch((err) => {
            uni.hideLoading();
          });
      }
    },
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/common/stylus/variable';

.page {
  position: relative;
  min-height: calc(100vh - var(--window-top));
  background: linear-gradient(180deg, #0d1523 0%, #102945 100%);

  .bg {
    position: absolute;
    z-index: 1;
    width: 100%;
  }
}

.main {
  position: relative;
  z-index: 2;
  padding: 0 30rpx;

  .intro {
    text-align: center;
    /* color: #fff; */
    color: color-white;
  }

  .bind {
    /* color: #fdfeff; */
    color: color-white;
    font-size: 44rpx;
    font-weight: bolder;
    padding-top: 170rpx;
  }

  .en {
    font-size: 26rpx;
    color: #8ea2c0;
    padding-top: 10rpx;
  }

  .hint {
    font-size: 28rpx;
    padding: 60rpx 0;
  }

  .v-label {
    /* color: #fdfeff; */
    color: color-desc;
    font-size: 24rpx;
    padding: 12rpx 0;
    margin-bottom: 30rpx;
  }

  .intro-input {
    border-radius: 4rpx;
    background-color: #1B345F;
    line-height: 88rpx;
    height: 88rpx;
    padding: 0 12rpx;
    // color: #fff;
    color: color-white;
  }
}

.page-head {
  position: fixed;
  z-index: 998;
  width: 100%;
  line-height: 64rpx;
  left: 0;
  top: 0;
  text-align: center;
  font-size: 36rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  transition: all 0.3s;
  color: color-white;
  padding-bottom: 12rpx;
  /* #ifdef H5 */
  line-height: 88rpx;
  padding-bottom: 0;
  /* #endif */
}
</style>